/* eslint-disable max-lines-per-function */
import { FormSchema } from '/@/components/BasicForm/type/form';

export const resourceSchema: FormSchema = [
  {
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'type',
    label: '资源类型',
    component: 'Select',
    componentProps: ({ formActionType }) => {
      return {
        placeHolder: '请选择资源类型',
        options: [
          {
            label: '菜单',
            value: 'MENU',
          },
          {
            label: '元素',
            value: 'ELEMENT',
          },
        ],
        onChange: (e) => {
          const { updateSchema } = formActionType;
          if (e === 'MENU') {
            updateSchema([
              {
                field: 'tempTitle',
                required: true,
              },
              {
                field: 'menuName',
                required: true,
              },
              {
                field: 'orderNo',
                required: true,
              },
              {
                field: 'icon',
                required: false,
              },
              {
                field: 'routePath',
                required: true,
              },
              {
                field: 'routeName',
                required: true,
              },
              {
                field: 'redirectPath',
                required: false,
              },
              {
                field: 'component',
                required: true,
              },
              {
                field: 'ifHideMenu',
                required: true,
              },
              {
                field: 'ifHideChildrenInMenu',
                required: true,
              },
              {
                field: 'ifHideBreadcrumb',
                required: true,
              },
            ]);
          } else {
            updateSchema([
              {
                field: 'tempTitle',
                required: false,
              },
              {
                field: 'menuName',
                required: false,
              },
              {
                field: 'orderNo',
                required: false,
              },
              {
                field: 'icon',
                required: false,
              },
              {
                field: 'routePath',
                required: false,
              },
              {
                field: 'routeName',
                required: false,
              },
              {
                field: 'redirectPath',
                required: false,
              },
              {
                field: 'component',
                required: false,
              },
              {
                field: 'ifHideMenu',
                required: false,
              },
              {
                field: 'ifHideChildrenInMenu',
                required: false,
              },
              {
                field: 'ifHideBreadcrumb',
                required: false,
              },
            ]);
          }
        },
      };
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'parentId',
    label: '父级资源',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入父级资源',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'name',
    label: '资源名称',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入资源名称',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'resourceName',
    label: '资源中文名称',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入资源中文名称',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'code',
    label: '编码',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入资源编码',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'version',
    label: '版本',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入版本',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'tempTitle',
    label: '菜单标题',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入菜单标题',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'menuName',
    label: '菜单名称',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入菜单名称',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'orderNo',
    label: '菜单顺序',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入菜单顺序',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'icon',
    label: '图标',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入图标',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'routePath',
    label: '路由路径',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入路由路径',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'routeName',
    label: '路由名称',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入路由名',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'redirectPath',
    label: '重定向路径',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入重定向路径',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'component',
    label: '组件',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入组件',
    },
    labelWidth: 100,
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'ifHideMenu',
    label: '隐藏菜单',
    component: 'Switch',
    componentProps: {
      checkedChildren: 'I',
      unCheckedChildren: 'O',
      checkedValue: true,
      unCheckedValue: false,
      defaultChecked: true,
    },
    labelWidth: 100,
    colProps: { span: 4 },
    required: false,
  },
  {
    field: 'ifHideChildrenInMenu',
    label: '隐藏子菜单',
    component: 'Switch',
    componentProps: {
      checkedChildren: 'I',
      unCheckedChildren: 'O',
      checkedValue: true,
      unCheckedValue: false,
      defaultChecked: true,
    },
    labelWidth: 100,
    colProps: { span: 4 },
    required: false,
  },

  {
    field: 'ifHideBreadcrumb',
    label: '隐藏面包屑',
    component: 'Switch',
    componentProps: {
      checkedChildren: 'I',
      unCheckedChildren: 'O',
      checkedValue: true,
      unCheckedValue: false,
      defaultChecked: true,
    },
    labelWidth: 100,
    colProps: { span: 4 },
    required: false,
  },
  {
    field: 'status',
    label: '状态',
    component: 'Switch',
    componentProps: {
      checkedChildren: 'I',
      unCheckedChildren: 'O',
      checkedValue: 1,
      unCheckedValue: 0,
      defaultChecked: 0,
    },
    labelWidth: 100,
    colProps: { span: 4 },
    required: false,
  },
];

export const resourceInfoSchema: FormSchema = [
  {
    field: 'type',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'parentId',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'name',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'resourceName',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'code',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'version',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'tempTitle',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'menuName',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'orderNo',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'icon',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'routePath',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'routeName',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'redirectPath',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'component',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'ifHideMenu',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'ifHideChildrenInMenu',
    dynamicDisabled: true,
    required: false,
  },

  {
    field: 'ifHideBreadcrumb',
    dynamicDisabled: true,
    required: false,
  },
  {
    field: 'status',
    dynamicDisabled: true,
    required: false,
  },
];
export const resourceNewSchema: FormSchema = [
  {
    field: 'type',
    dynamicDisabled: false,
    required: true,
    componentProps: ({ formActionType }) => {
      return {
        placeHolder: '请选择资源类型',
        options: [
          {
            label: '菜单',
            value: 'MENU',
          },
          {
            label: '元素',
            value: 'ELEMENT',
          },
        ],
        onChange: (e) => {
          const { updateSchema } = formActionType;
          if (e === 'MENU') {
            updateSchema([
              {
                field: 'tempTitle',
                required: true,
              },
              {
                field: 'menuName',
                required: true,
              },
              {
                field: 'orderNo',
                required: true,
              },
              {
                field: 'icon',
                required: false,
              },
              {
                field: 'routePath',
                required: true,
              },
              {
                field: 'routeName',
                required: true,
              },
              {
                field: 'redirectPath',
                required: false,
              },
              {
                field: 'component',
                required: true,
              },
              {
                field: 'ifHideMenu',
                required: true,
              },
              {
                field: 'ifHideChildrenInMenu',
                required: true,
              },
              {
                field: 'ifHideBreadcrumb',
                required: true,
              },
            ]);
          } else {
            updateSchema([
              {
                field: 'tempTitle',
                required: false,
              },
              {
                field: 'menuName',
                required: false,
              },
              {
                field: 'orderNo',
                required: false,
              },
              {
                field: 'icon',
                required: false,
              },
              {
                field: 'routePath',
                required: false,
              },
              {
                field: 'routeName',
                required: false,
              },
              {
                field: 'redirectPath',
                required: false,
              },
              {
                field: 'component',
                required: false,
              },
              {
                field: 'ifHideMenu',
                required: false,
              },
              {
                field: 'ifHideChildrenInMenu',
                required: false,
              },
              {
                field: 'ifHideBreadcrumb',
                required: false,
              },
            ]);
          }
        },
      };
    },
  },
  {
    field: 'parentId',
    dynamicDisabled: false,
    required: true,
  },
  {
    field: 'name',
    dynamicDisabled: false,
    required: true,
  },
  {
    field: 'resourceName',
    dynamicDisabled: false,
    required: true,
  },
  {
    field: 'code',
    dynamicDisabled: false,
    required: true,
  },
  {
    field: 'version',
    dynamicDisabled: false,
    required: true,
  },
  {
    field: 'tempTitle',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'menuName',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'orderNo',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'icon',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'routePath',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'routeName',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'redirectPath',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'component',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'ifHideMenu',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'ifHideChildrenInMenu',
    dynamicDisabled: false,
    required: false,
  },

  {
    field: 'ifHideBreadcrumb',
    dynamicDisabled: false,
    required: false,
  },
  {
    field: 'status',
    dynamicDisabled: false,
    required: true,
  },
];

export const apiSchema: FormSchema = [
  {
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    componentProps: {
      placeHolder: '请选择名称',
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'resourceName',
    label: '中文名称',
    component: 'Input',
    componentProps: {
      placeHolder: '请选择中文名称',
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'code',
    label: '编码',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入编码',
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'apiUrl',
    label: '接口地址',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入接口地址',
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'method',
    label: '请求方式',
    component: 'Select',
    componentProps: {
      placeHolder: '请选择请求方式',
      options: [
        {
          label: 'POST',
          value: 'POST',
        },
        {
          label: 'GET',
          value: 'GET',
        },
        {
          label: 'PUT',
          value: 'PUT',
        },
        {
          label: 'DELETE',
          value: 'DELETE',
        },
      ],
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'version',
    label: '版本',
    component: 'Input',
    componentProps: {
      placeHolder: '请输入版本',
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'status',
    label: '状态',
    component: 'Switch',
    componentProps: {
      checkedChildren: 'I',
      unCheckedChildren: 'O',
      checkedValue: 1,
      unCheckedValue: 0,
      defaultChecked: 0,
    },
    labelWidth: 100,
    colProps: { span: 24 },
    required: true,
  },
];
export const apiColumns = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 150,
  },
  {
    title: '中文名称',
    dataIndex: 'resourceName',
    width: 150,
  },
  {
    title: '编码',
    dataIndex: 'code',
    width: 150,
  },
  {
    title: '接口地址',
    dataIndex: 'apiUrl',
    width: 150,
  },
  {
    title: '请求方式',
    dataIndex: 'method',
    width: 150,
  },
  {
    title: '版本',
    dataIndex: 'version',
    width: 150,
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({ record }) => {
      return record.status === 1 ? '启用' : '停用';
    },
    width: 150,
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 100,
  },
];

export const menuChange = [
  {
    field: 'tempTitle',
    required: true,
  },
  {
    field: 'menuName',
    required: true,
  },
  {
    field: 'orderNo',
    required: true,
  },
  {
    field: 'icon',
    required: false,
  },
  {
    field: 'routePath',
    required: true,
  },
  {
    field: 'routeName',
    required: true,
  },
  {
    field: 'redirectPath',
    required: false,
  },
  {
    field: 'component',
    required: true,
  },
  {
    field: 'ifHideMenu',
    required: true,
  },
  {
    field: 'ifHideChildrenInMenu',
    required: true,
  },
  {
    field: 'ifHideBreadcrumb',
    required: true,
  },
];
